<template>
  <div style="height: 100%; width: 100%; position: relative">
      <div class="pagetop">
          <div style="width: 100%; float: left">
              <table style="width: 100%; font-size: 12px; white-space: nowrap" border="0" class="table1style">
                  <col style="width: 5%" />
                  <col style="width: 10%" />
                  <col style="width: 5%" />
                  <col style="width: 12%" />
                  <col style="width: 5%" />
                  <col style="width: 10%" />
                  <col style="width: 5%" />
                  <col style="width: 10%" />
                  <col style="width: 4%" />
                  <col style="width: 10%" />
                  <col style="width: 5%" />
                  <col style="width: 10%" />
                  <col style="width: 5%" />
                  <col style="width: 10%" />
                  <col style="width: 5%" />
                  <tr>
                      <td align="right">报告单元</td>
                      <td>
                          <rm-ddl-rptunit prgno="LIS330" v-model="txtrptunit" clearable filterable @change="handlerrptitemchange($event)" :appendtobody="true" visible-change:true width="210px"></rm-ddl-rptunit>
                      </td>
                      <td align="right">标 本 号</td>
                      <td>
                          <el-input v-model="txtsampleno" placeholder=""></el-input>
                      </td>
                      <td align="right">病历号</td>
                      <td>
                          <el-input v-model="txtpatno" placeholder=""></el-input>
                      </td>
                      <td align="right">病人来源</td>
                      <td>
                          <rm-ddl-common datatype="seccode" kindno="PT" dataname="病人来源" v-model="txtpattypecode" width="130px"></rm-ddl-common>
                      </td>
                      <td align="right">病区</td>
                      <td>
                          <rm-ddl-common :appendtobody="true" datatype="ward" dataname="病区" v-model="txtwardno" width="100%"></rm-ddl-common>
                      </td>
                      <td align="right">急诊标志</td>
                      <el-select v-model="txtemer" placeholder="">
                          <el-option v-for="(item, index) in emerOptions" :key="index" :value="item.value" :label="item.label"></el-option>
                      </el-select>
                      <td>
                          <el-checkbox true-label="1" false-label="0" v-model="txthaveprint">打印过的标本</el-checkbox>
                      </td>
                      <td>
                          <el-checkbox true-label="1" false-label="0" v-model="showRedo">不显示需复查报告</el-checkbox>
                      </td>
                  </tr>
                  <tr>
                      <td align="right">报告日期</td>
                      <td>
                          <el-date-picker v-model="txtrptDatetime" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" :default-time="['00:00:00', '23:59:59']" size="mini" :clearable="false" style="width: 210px"></el-date-picker>
                      </td>
                      <td align="right">条 码 号</td>
                      <td>
                          <el-input v-model="txtbarcode" placeholder=""></el-input>
                      </td>
                      <td align="right">姓 名</td>
                      <td>
                          <el-input v-model="txtpatname" placeholder=""></el-input>
                      </td>
                      <td align="right">申请科室</td>
                      <td>
                          <rm-ddl-common datatype="dept" dataname="科室" v-model="txtdeptno" width="130px"></rm-ddl-common>
                      </td>
                      <td align="right">床号</td>
                      <td>
                          <el-input v-model="txtbedno" placeholder=""></el-input>
                      </td>
                      <td align="right">审核状态</td>
                      <td>
                          <el-select v-model="txtchkstate" placeholder="" style="width: 100%">
                              <el-option v-for="(item, index) in chkOptions" :key="index" :value="item.value" :label="item.label"></el-option>
                          </el-select>
                      </td>

                      <td>
                          <el-checkbox true-label="1" false-label="0" v-model="txtpeacefalmod">安静模式</el-checkbox>
                      </td>
                      <td>
                          <el-checkbox true-label="1" false-label="0" v-model="aftercheckautoprint">审核后自动打印</el-checkbox>
                      </td>
                  </tr>
                  <tr>
                      <td align="right">项目组合</td>
                      <td>
                          <rm-ddl-common datatype="reportitemcomb" dataname="项目组合" v-model="txtitemcombid" width="100%" :labgroupid="labgroupid"></rm-ddl-common>
                      </td>
                  </tr>
              </table>
          </div>
          <div style="width: 100%; float: left">
              <table style="float: right">
                  <tr>
                      <td>
                          <el-button type="primary" @click="btnQuery">查询</el-button>
                      </td>
                      <td>
                          <el-button @click="btnSort">排序</el-button>
                      </td>
                      <td>
                          <el-button @click="btnClear">清除</el-button>
                      </td>
                      <td>
                          <el-button @click="btnPrint">打印</el-button>
                      </td>
                      <td>
                          <el-button @click="btnExport">导出</el-button>
                      </td>
                      <td>
                          <el-button @click="btnBatchCheck">批次审核</el-button>
                      </td>
                      <td>
                          <el-button @click="btnBatchUnCheck">批次解审</el-button>
                      </td>
                      <td>
                          <el-button @click="btnUnSign">批次解签</el-button>
                      </td>
                      <td>
                          <el-button @click="btnRefreshRef">刷新参考值</el-button>
                      </td>
                  </tr>
              </table>
          </div>
      </div>
      <div class="pagecenter">
          <rm-layout-right splitcolor="#FFFFFF" movingcolor="#66CCFF" :splitwidth="5" :fixsize="400">
              <template v-slot:fix>
                  <vxe-table :data.sync="RightTableData" height="auto" highlight-current-row :loading="xTable2loading" highlight-hover-row highlight-hover-column resizable show-header-overflow="tooltip" border fit show-overflow="tooltip" header-align="center" size="mini" stripe ref="xTable2">
                      <!-- <vxe-table-column type="index" title="NO." width="60"></vxe-table-column> -->
                      <!--如果在循环里面这样加，双击表头会消失，暂时去除-->
                      <vxe-table-column :field="items.field" :key="items.field" :title="items.title" :width="items.width" sortable v-for="items in RightTableColumn" :formatter="formatterFun">
                          <template v-slot="{ row }" v-if="items.field == 'result_str'">
                              <div :style="ResultClass(row)">
                                  <span v-if="Options.resultstrbold == '1'" style="font-weight: bold">{{ row.result_str }}</span>
                                  <span v-else>{{ row.result_str }}</span>
                              </div>
                          </template>
                      </vxe-table-column>
                  </vxe-table>
              </template>
              <div style="height: 100%; width: 100%; background-color: #ddccbb">
                  <vxe-table show-overflow ref="xTable1" height="auto" :loading="xTable1loading" :cell-class-name="cellClassName" :sort-config="{ trigger: 'cell' }" :keyboard-config="keyConfig" :data.sync="LeftTableData" border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe @current-change="currentChangeEvent" header-align="center">
                      <vxe-table-column type="selection" width="45" align="center"></vxe-table-column>
                      <vxe-table-column field="sampledate" title="标本日期" width="80" sortable :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                      <vxe-table-column field="sampleno" title="标本编号" width="60" align="center"></vxe-table-column>
                      <vxe-table-column field="pat_name" title="姓名" width="50" sortable></vxe-table-column>
                      <vxe-table-column field="pat_no" title="病人号" width="90"></vxe-table-column>
                      <vxe-table-column field="pat_sex" title="性别" width="40" align="center" :formatter="formatterFun"></vxe-table-column>
                      <vxe-table-column field="pat_agestr" title="年龄" width="50"></vxe-table-column>
                      <vxe-table-column field="specimen_code" title="标本类型" width="60" :formatter="formatterFun"> </vxe-table-column>
                      <vxe-table-column field="rechk_username" title="审核医生" width="60" align="center"> </vxe-table-column>
                      <vxe-table-column field="rechk_dt" title="审核时间" width="80" :formatter="['toDateString', 'yyyy-MM-dd']" align="center"> </vxe-table-column>
                      <vxe-table-column field="cp_msg" title="审核消息提示" width="100" align="center">
                          <template v-slot="{ row }">
                              <div :style="ResultClass1(row)">
                                  <span>{{ row.cp_msg }}</span>
                              </div>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="report_username" title="检验医生" width="60" align="center"></vxe-table-column>
                      <vxe-table-column field="report_dt" title="报告时间" width="80" align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                      <vxe-table-column field="rptunitid" title="报告单元ID" width="90"></vxe-table-column>
                      <vxe-table-column field="redo_flagname" title="复查" width="40" align="center"> </vxe-table-column>
                      <vxe-table-column field="emer_flag" title="加急" width="40" align="center" :formatter="formatterFun">
                          <!-- <template v-slot="{row}">
                              <el-checkbox v-model="row.emer_flag" true-label="1" false-label="0" disabled></el-checkbox>
                          </template> -->
                      </vxe-table-column>
                      <!-- <vxe-table-column field="warn_flag" title="警告" width="40" align="center">
                          <template v-slot="{row}">
                              <el-checkbox v-model="row.warn_flag" true-label="1" false-label="0" disabled></el-checkbox>
                          </template>
                      </vxe-table-column> -->
                      <vxe-table-column field="req_bedno" title="床号" width="50" align="center"></vxe-table-column>
                      <vxe-table-column field="pat_typecode" title="病人类别" width="60" :formatter="formatterFun"></vxe-table-column>
                      <vxe-table-column field="barcode" title="条码号" width="80"></vxe-table-column>
                      <vxe-table-column field="req_deptno" title="申请科室" width="80" :formatter="formatterFun"> </vxe-table-column>
                      <vxe-table-column field="req_wardno" title="病人病区" width="80" :formatter="formatterFun"></vxe-table-column>
                      <vxe-table-column field="charge_typeno" title="收费类别" width="60"> </vxe-table-column>
                      <vxe-table-column field="pat_diag" title="临床诊断" width="120"></vxe-table-column>
                      <vxe-table-column field="req_dt" title="申请时间" width="120" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                      <vxe-table-column field="req_docno" title="申请医生" width="80"></vxe-table-column>
                      <vxe-table-column field="sampled_dt" title="采样时间" width="120" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                      <vxe-table-column field="recieve_dt" title="接收时间" width="120" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                      <vxe-table-column field="input_dt" title="录入时间" width="120" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                      <vxe-table-column field="test_info" title="上机信息" width="70"></vxe-table-column>
                      <vxe-table-column field="test_dt" title="上机时间" width="80" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                      <vxe-table-column field="report_comm" title="报告单备注" width="120"></vxe-table-column>
                      <vxe-table-column field="lab_advice" title="实验室意见" width="90"></vxe-table-column>
                      <vxe-table-column field="item_num" title="项目数" width="60" align="center"></vxe-table-column>
                      <vxe-table-column field="instr_advice" title="仪器辅助诊断" width="90"></vxe-table-column>
                      <vxe-table-column field="rechk2_dt" title="二审时间" width="80" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                      <vxe-table-column field="rechk2_user" title="二审医生" width="70"></vxe-table-column>
                      <vxe-table-column field="lastprint_dt" title="最后打印时间" width="90" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                      <vxe-table-column field="print_count" title="打印次数" width="60" align="center"></vxe-table-column>
                      <!-- <vxe-table-column field="rpt_itemname" title="计价" width="130"></vxe-table-column> -->
                      <vxe-table-column field="prereport_dt" title="预计报告时间" width="90" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                      <vxe-table-column field="reportid" title="报告ID" width="80"></vxe-table-column>
                      <vxe-table-column field="hospcode" title="医院代码" width="80"></vxe-table-column>
                      <vxe-table-column field="specimen_comm" title="样本状态备注" width="110"></vxe-table-column>
                      <vxe-table-column field="pat_cardno" title="就诊卡号" width="100"></vxe-table-column>
                      <vxe-table-column field="inp_id" title="就诊号" width="70"></vxe-table-column>
                      <vxe-table-column field="inp_date" title="入院日期" width="90" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                      <vxe-table-column field="pat_phone" title="联系电话" width="90"></vxe-table-column>
                      <vxe-table-column field="pat_id" title="病人ID" width="80"></vxe-table-column>
                      <vxe-table-column field="rowversion" title="最后修改时间" width="100" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                      <vxe-table-column field="release_dt" title="发布时间" width="80" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                      <vxe-table-column field="release_user" title="发布人" width="70"></vxe-table-column>
                      <vxe-table-column field="req_reason" title="送检目的" width="120"></vxe-table-column>
                      <vxe-table-column field="is_changed" title="是否修改" width="70" align="center"></vxe-table-column>
                      <vxe-table-column field="changed_afterreport" title="打印、审核后修改" width="120" align="center"></vxe-table-column>
                      <vxe-table-column field="unprint_flag" title="禁止打印标志" width="90" align="center"></vxe-table-column>
                      <vxe-table-column field="unprint_reason" title="禁止打印原因" width="120"></vxe-table-column>
                      <vxe-table-column field="exprint_count" title="外部打印次数" width="90" align="center"></vxe-table-column>
                  </vxe-table>
              </div>
          </rm-layout-right>
      </div>

      <!--危急值上报弹窗-->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="危急值上报" :visible.sync="dialogDangerVisible" v-if="dialogDangerVisible" ref="dangerdialog" width="900px">
          <rm-pop-danger :reportid="reportid" :rptunitid="rptunitid" :checkuser="CurrentCheckUser" @confirm="CheckDangerDeal($event, 1)" @abandon="CheckDangerDeal($event, 2)" @cancel="dialogDangerVisible = false"></rm-pop-danger>
      </el-dialog>

      <!--消息弹出框可回看式-->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialogMsgVisible" :title="msgtitle" :destroy-on-close="true" top="5vh" width="600px" ref="msgdialog" @close="$refs.msgdialog.Cancel()">
          <el-carousel trigger="click" height="200px" :autoplay="false" :loop="false" arrow="always" @change="MsgCarouselChange">
              <el-carousel-item v-for="(item, index) in msglist" :key="index">
                  <div style="width: 80%; margin-left: 50px">
                      <div v-if="item.keycode" v-html="item.msg.title"></div>
                      <div v-else v-html="item.content" style="height: 100px"></div>
                      <div v-if="item.keycode" style="padding-top: 5px">
                          <el-input v-model="inmsg" type="textarea" :rows="8" @dblclick.native="msgDblClick(item.msg.content, item.keycode)" placeholder="双击开窗选择解除审核原因" v-if="item.msg.content.indexOf('解除审核') > -1"></el-input>
                          <el-input type="textarea" :rows="2" v-model="inmsg" v-else></el-input>
                          <el-button @click="SaveInputMsg(item.keycode)">保存</el-button>
                      </div>
                  </div>
              </el-carousel-item>
          </el-carousel>
          <div style="text-align: right">
              <span style="margin-right: 5px">{{ NowMsgNo }}/{{ TotalMsgNo }} 翻页查看所有消息后才可确定</span>
              <el-button @click="$refs.msgdialog.Confirm()" :disabled="MsgAllOver || Submitdisabled">确 定</el-button>
              <el-button @click="$refs.msgdialog.Cancel()">取 消</el-button>
          </div>
      </el-dialog>
      <!--解除审核原因框-->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="解除审核原因" ref="uncheckdialog" :visible.sync="dialogUnCkeclReasonVisible">
          <div v-if="inputkeycode">
              <el-input type="textarea" rows="5" v-model="unreasoncheckmsg" @dblclick.native="msgDblClick" placeholder="双击开窗选择解除审核原因" @input="uncheckInput"></el-input>
          </div>
          <div style="text-align: right">
              <el-button @click="$refs.uncheckdialog.Confirm()" :disabled="SingleSubmitdisabled">确 定</el-button>
              <el-button @click="$refs.uncheckdialog.Cancel()">取 消</el-button>
          </div>
      </el-dialog>
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="解除审核原因" :visible.sync="dialogUncheckReasonDataVisible" v-if="dialogUncheckReasonDataVisible">
          <rm-pop-common datatype="seccode" kindno="RPTUNCHKREASON" dataname="解除审核原因" @cancel="dialogUncheckReasonDataVisible = false" @change="Uncheckchange"></rm-pop-common>
      </el-dialog>

      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialogSingleMsgVisible" :title="SingleMsgTitle" :destroy-on-close="true" top="5vh" width="400px" ref="singlemsgdialog">
          <div>
              <div class="el-message-box__content">
                  <div class="el-message-box__status el-icon-warning"></div>
                  <div class="el-message-box__message">
                      <p>{{ SingleMsgContent }}</p>
                  </div>
              </div>
              <div class="el-message-box__btns">
                  <el-checkbox v-model="IgnoreFlag">后续忽略</el-checkbox>
                  <el-button @click="$refs.singlemsgdialog.Confirm()" ref="confirm">确定</el-button>
                  <el-button @click="$refs.singlemsgdialog.Cancel()" v-show="ShowCancel" ref="cancel">取消</el-button>
              </div>
          </div>
      </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "LIS330",
  data() {
      return {
          txtrptunit: "",
          txtbarcode: "",
          txtsampleno: "",
          txtpatname: "",
          txtdeptno: "",
          txtbedno: "",
          txtrptDatetime: ["", ""],
          txtpattypecode: "",
          txtwardno: "",
          txtpatno: "",
          txtemer: "",
          txtchkstate: "D",
          txthaveprint: "0",
          txtpeacefalmod: "1",
          aftercheckautoprint: "0",
          txtitemcombid: "",
          showRedo: "0",
          xTable1loading: false,
          xTable2loading: false,
          pattypeOption: [],
          deptOption: [],
          wardOption: [],
          Options: {},
          rptunitOptions: {},
          useca: "0",
          //userOption: [],
          specimenOption: [],
          emerOptions: [
              { label: "常规", value: "0" },
              { label: "急诊", value: "1" },
          ],
          chkOptions: [
              { label: "全部", value: "-1" },
              { label: "待审", value: "D" },
              { label: "未审", value: "0" },
              { label: "签名", value: "1" },
              { label: "初审", value: "2" },
              { label: "已审核", value: "9" },
          ],
          RightTableColumn: [],
          RightTableData: [],
          LeftTableData: [],
          tableColumn: [],
          sortArr: [],
          selectConfig: { tigger: "row" }, //vxe表格选中方式
          keyConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
              isArrow: true,
          },
          CheckUser: "",
          CheckUserName: "",
          dialogDangerVisible: false,
          CurrentCheckUser: { userno: "", username: "" }, //当前审核用户
          reportid: "",
          rptunitid: "",
          InputMsg: "",
          combineArr: [],
          //消息提示框
          dialogMsgVisible: false,
          dialogUnCkeclReasonVisible: false,
          dialogUncheckReasonDataVisible: false,
          inputkeycode: "",
          unreasoncheckmsg: "",
          msgtitle: "提示",
          msgcontent: "",
          Submitdisabled: true,
          SingleSubmitdisabled: true,
          MsgInputShow: false,
          MsgInputMsg: "",
          inmsg: "", //输入消息单条
          msglist: [],
          NowMsgNo: 0,
          TotalMsgNo: 0,
          MsgAllOver: true, //消息看到最后标志
          tempIgnoreList: [],
          //审核用内容
          CheckRows: [], //需要审核的报告集合
          checkindex: 0, //当前审核到的行
          checksuccess: 0, //审核成功的行数
          checkfail: 0, //审核失败行数
          checkcafail: 0, //审核ca失败
          UnCheckRows: [], //需要审核的报告集合
          Uncheckindex: 0, //当前审核到的行
          unchecksuccess: 0, //解除审核成功的行数
          uncheckfail: 0, //解除审核失败行数
          rechkcoverechkuser: "0",
          //单消息提示框--用于后续忽略
          dialogSingleMsgVisible: false,
          SingleMsgTitle: "提示",
          SingleMsgContent: "",
          IgnoreFlag: true, //后续忽略勾选
          ShowCancel: true,
          focusOnCancel: false,
          labgroupid: 0,
      };
  },
  created() {
      this.initOption();
      this.InitDate(); //初始化主列表
      this.InitPage(); //初始化查询
  },
  mounted() {},
  updated() {},
  methods: {
      initOption() {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS330",
                  method: "post",
                  data: {
                      action: "initOption",
                  },
              })
              .then((res) => {
                  if (!res.hasOwnProperty("errcode")) {
                      this.pattypeOption = res.pattypeOption;
                      this.deptOption = res.deptOption;
                      this.wardOption = res.wardOption;
                      // this.userOption = res.userOption;
                      this.specimenOption = res.specimenOption;
                      this.txtrptunit = res.defaultrptunitid;
                      this.useca = res.useca;
                      this.Options = res.Options;
                      this.labgroupid = parseInt(res.labgroupid);
                  }
              });
      },
      InitDate() {
          var day1 = new Date();
          day1.setTime(day1.getTime());
          var s1 = day1.getFullYear() + "-" + (day1.getMonth() + 1) + "-" + day1.getDate() + " 23:59:59";
          var day2 = new Date();
          day2.setTime(day2.getTime());
          var s2 = day2.getFullYear() + "-" + (day2.getMonth() + 1) + "-" + day2.getDate() + " 00:00:00";
          this.txtrptDatetime = [s2, s1];
      },
      InitPage() {
          this.xTable1loading = true;
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS330",
                  method: "post",
                  data: {
                      action: "InitPage",
                      txtrptunit: this.txtrptunit,
                      txtbarcode: this.txtbarcode,
                      txtsampleno: this.txtsampleno,
                      txtpatname: this.txtpatname,
                      txtdeptno: this.txtdeptno,
                      txtbedno: this.txtbedno,
                      txtpattypecode: this.txtpattypecode,
                      txtwardno: this.txtwardno,
                      txtpatno: this.txtpatno,
                      txtemer: this.txtemer,
                      txtchkstate: this.txtchkstate,
                      txtstarttime: this.txtrptDatetime[0],
                      txtendtime: this.txtrptDatetime[1],
                      haveprint: this.txthaveprint,
                      sortArr: this.sortArr,
                      showredo: this.showRedo,
                      txtitemcombid: this.txtitemcombid,
                  },
              })
              .then((response) => {
                  this.LeftTableData = response.Data;
                  this.loadFirstRow(this.$refs.xTable1, this.currentChangeEventFun);
                  this.xTable1loading = false;
                  this.rechkcoverechkuser = response.rechkcoverechkuser;
              })
              .catch((e) => {
                  this.xTable1loading = false;
                  this.$message.warning(e.message);
              });
      },
      //自动加载表格的第一行，并执行回调函数
      loadFirstRow(xTable, func) {
          this.$nextTick(() => {
              // 加载第一行
              var selectrow = xTable.getData(0);
              if (selectrow) {
                  xTable.setCurrentRow(selectrow); //高亮行
                  xTable.scrollToRow(selectrow); //滚动到行
                  this.currentChangeEventFun(selectrow);
                  if (typeof func == "function") func(selectrow.reportid);
              } else {
                  xTable.setCurrentRow(null); //这个不会自动清空
                  func("");
              }
          });
      },
      formatterFun({ row, column, cellValue }) {
          if (column.property == "pat_sex") {
              if (cellValue == "1") {
                  return "男";
              } else if (cellValue == "2") {
                  return "女";
              } else {
                  return "";
              }
          } else if (column.property == "emer_flag") {
              if (cellValue == "1") {
                  return "急";
              } else {
                  return "";
              }
          } else if (column.property == "last_dt") {
              return XEUtils.toDateString(cellValue, "yyyy-MM-dd");
          } else if (column.property == "pat_typecode") {
              try {
                  let k = this.pattypeOption.find((m) => m.value == cellValue).label;
                  if (k) {
                      return k;
                  } else {
                      return cellValue;
                  }
              } catch (e) {
                  return cellValue;
              }
          } else if (column.property == "specimen_code") {
              try {
                  let k = this.specimenOption.find((m) => m.data == cellValue).display;

                  if (k) {
                      return k;
                  } else {
                      return cellValue;
                  }
              } catch (e) {
                  return cellValue;
              }
          } else if (column.property == "req_deptno") {
              try {
                  let k = this.deptOption.find((m) => m.data == cellValue).display;
                  if (k) {
                      return k;
                  } else {
                      return cellValue;
                  }
              } catch (e) {
                  return cellValue;
              }
          } else if (column.property == "req_wardno") {
              try {
                  let k = this.wardOption.find((m) => m.data == cellValue).display;
                  if (k) {
                      return k;
                  } else {
                      return cellValue;
                  }
              } catch (e) {
                  return cellValue;
              }
          }
          // else if (column.property == "rechk_user") {
          //     try {
          //         let k = this.userOption.filter((m) => m.data == cellValue);
          //         console.log("sa", k);
          //         if (k.length>0) {
          //             return k[0].display;
          //         } else {
          //             return cellValue;
          //         }
          //     } catch (e) {
          //         return cellValue;
          //     }
          // }
          else {
              return cellValue;
          }
      },
      currentChangeEvent({ row }) {
          this.currentChangeEventFun(row.reportid);
      },
      async currentChangeEventFun(rowreportid) {
          try {
              this.xTable2loading = true;
              const res = await this.$tool.request({
                  url: "LIS/LIS3/LIS330",
                  method: "post",
                  data: {
                      action: "getReportResult",
                      reportid: rowreportid,
                  },
              });
              this.RightTableData = res.RData.Data;
              this.RightTableColumn = res.RData.Cols;
              this.xTable2loading = false;
          } catch (e) {
              this.$message.warning(e);
          }
      },
      cellClassName({ row, column }) {
          if (column.property == "redo_flagname") {
              if (row.redo_flag == "1") {
                  return "col-yellow";
              } else if (row.redo_flag == "2") {
                  return "col-green";
              } else {
                  return "";
              }
          } else if (column.property == "emer_flag") {
              if (row.emer_flag == "1") {
                  return "col-red";
              } else {
                  return "";
              }
          } else if (column.property == "warn_flag") {
              if (row.warn_flag == "1") {
                  console.log("row.warn_flag ", row.warn_flag);
                  return "col-red";
              } else {
                  return "";
              }
          }
      },
      ResultClass(row, type) {
          var stylestr = "padding:0 3px;";
          if (this.Options.resultcolor_mode == "1") stylestr += "color:";
          else stylestr += "background-color:";
          var flag = row.result_flag;
          switch (flag) {
              case "M":
                  stylestr += this.Options.resultcolor_m;
                  break;
              case "H":
                  stylestr += this.Options.resultcolor_h;
                  break;
              case "L":
                  stylestr += this.Options.resultcolor_l;
                  break;
              case "P":
                  stylestr += this.Options.resultcolor_p;
                  break;
              case "W":
                  stylestr += this.Options.resultcolor_w;
                  break;
              case "E":
                  stylestr += this.Options.resultcolor_e;
                  break;
              case "Q":
                  stylestr += this.Options.resultcolor_r;
                  break;
              default:
                  stylestr += this.Options.resultcolor_m;
                  break;
          }
          if (row.result_str == "未做") {
              stylestr += ";color: #0095D9";
          }
          return stylestr;
      },
      handlerrptitemchange(e) {},
      btnQuery() {
          this.InitPage();
      },
      btnSort() {
          if (this.tableColumn.length == 0) {
              let columns = this.$refs.xTable1.getColumns();
              columns.forEach((item) => {
                  this.tableColumn.push({ title: item.title, field: item.property });
              });
          }
          this.$rmsort(
              { tableColumn: this.tableColumn, sortArr: this.sortArr },
              {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
              }
          )
              .then((res) => {
                  this.sortArr = res.data;
                  this.InitPage();
              })
              .catch(() => {});
      },
      btnClear() {
          this.InitDate();
          this.txtrptunit = "";
          this.txtbarcode = "";
          this.txtsampleno = "";
          this.txtpatname = "";
          this.txtdeptno = " ";
          this.txtbedno = "";
          this.txtpattypecode = " ";
          this.txtwardno = " ";
          this.txtpatno = "";
          this.txtemer = "";
          this.txtchkstate = "";
          this.txthaveprint = "0";
          this.txtpeacefalmod = "1";
          this.aftercheckautoprint = "0";
          this.txtitemcombid = "";
      },
      btnPrint() {},
      btnExport() {},
      //批次审核
      btnBatchCheck() {
          this.checksuccess = 0;
          this.checkfail = 0;
          this.checkcafail = 0;
          this.CheckReport();
      },
      //批次解审
      btnBatchUnCheck() {
          this.unchecksuccess = 0;
          this.uncheckfail = 0;
          this.UnCheckReport();
      },
      btnRefreshRef() {},
      //CA认证
      checkCaLogin(rckuser) {
          return new Promise((s, f) => {
              if (this.useca == "1") {
                  this.$ca.checklogin("rptchk", rckuser).then((cares) => {
                      s(cares);
                  });
              } else {
                  s({ flag: "1" });
              }
          });
      },
      //审核报告
      CheckReport() {
          var rows = this.$refs.xTable1.getSelectRecords();
          this.CheckRows = rows;
          this.checkindex = 0;
          var hasrows = this.CheckRows.filter((item) => item.reportid != "");
          if (hasrows.length == 0) {
              this.$alert("没有选中需要审核的报告!", "提示");
              return;
          }
          var checkrows = this.CheckRows.filter((item) => item.rechkflag != "9");
          if (checkrows.length == 0) {
              this.$alert("选中报告已经全部审核,无需再审!", "提示");
              return;
          }
          this.checkindex = this.CheckRows.indexOf(checkrows[0]);
          if (this.CheckUser) {
              this.BeforeCheckReport(this.CheckRows[this.checkindex]);
          } else {
              this.$rm_Login({
                  type: "请输入审核者工号和密码",
                  btn: {
                      confirmBtnText: "确定",
                      cancelBtnText: "取消",
                  },
              })
                  .then((res) => {
                      if (res.flag == "1") {
                          this.checkCaLogin(res.userid).then((cares) => {
                              if (cares.flag == "1") {
                                  this.CheckUser = res.userid;
                                  this.CheckUserName = res.username;
                                  this.combineArr = [];
                                  this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                              } else {
                                  this.$alert("CA登录失败！" + cares.msg, "登陆失败", {
                                      confirmButtonText: "确定",
                                      type: "error",
                                  });
                              }
                          });
                      } else {
                          //登录失败
                      }
                  })
                  .catch((e) => {
                      console.log("error", e.message);
                  });
          }
      },
      BeforeCheckReport(row) {
          //this.xTable1loading = true;
          let rckuser = !row.rechk_user ? this.CheckUser : row.rechk_user;
          let rckusername = !row.rechk_username ? this.CheckUserName : row.rechk_username;
          if (this.rechkcoverechkuser == "1") {
              rckuser = this.CheckUser;
              rckusername = this.CheckUserName;
          }
          this.checkCaLogin(rckuser).then((cares) => {
              if (cares.flag == "1") {
                  //this.$pub.Log("LIS330 批次审核: 开始审核报告" + row.reportid);
                  this.$pub.Log("LIS330 批次审核：开始审核报告 检验用户=" + row.report_user + ",审核用户=" + rckuser + ",reportid = " + row.reportid);
                  this.$tool
                      .request({
                          url: "LIS/LIS3/LIS330",
                          method: "post",
                          data: {
                              action: "checkreport",
                              reportid: row.reportid,
                              reportuser: row.report_user,
                              checkuser: rckuser,
                          },
                      })
                      .then((res) => {
                          this.$pub.Log("LIS330 批次审核: 审核报告后台请求结束" + row.reportid);
                          if (res.flag == 1 || res.flag == 2) {
                              //如果安静模式
                              if (res.alertflag == 1) {
                                  if (this.txtpeacefalmod == "1") {
                                      //this.CheckRows[this.checkindex].cp_msg = "审核失败";
                                      if (res.msg.errorMsg != null && res.msg.errorMsg.length > 0) {
                                          this.CheckRows[this.checkindex].cp_msg = "审核失败:" + res.msg.errorMsg[0].content;
                                      } else {
                                          this.CheckRows[this.checkindex].cp_msg = "审核失败";
                                      }
                                      this.CheckRows[this.checkindex].cp_flag = -1;
                                      this.checkindex++;
                                      this.checkfail++;
                                      this.$pub.Log("LIS330 批次审核: 审核报告置值结束 审核失败" + row.reportid);
                                      if (this.checkindex < this.CheckRows.length) this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                                      else {
                                          this.AlertMsg();
                                      }
                                  } else {
                                      this.reportid = row.reportid;
                                      this.rptunitid = row.rptunitid;
                                      this.dialogDangerVisible = true;
                                      this.CurrentCheckUser = { userno: rckuser, username: rckusername };
                                  }
                              } else {
                                  //安静模式或者无危急值上报
                                  this.ReportCheckCA(res, "", rckuser)
                                      .then(() => {
                                          this.CheckRows[this.checkindex].rechk_user = rckusername;
                                          this.CheckRows[this.checkindex].rechk_dt = XEUtils.toDateString(new Date(), "yyyy-MM-dd");
                                          this.CheckRows[this.checkindex].cp_msg = "审核成功";
                                          this.checkindex++;
                                          this.checksuccess++;
                                          this.$pub.Log("LIS330 批次审核: 审核报告置值结束 审核成功" + row.reportid);
                                          if(this.aftercheckautoprint == "1") this.singleprint(row.reportid);
                                          if (this.checkindex < this.CheckRows.length) this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                                          else {
                                              this.xTable1loading = false;
                                              this.AlertMsg();
                                          }
                                      })
                                      .catch(() => {
                                          this.CheckRows[this.checkindex].rechk_user = rckusername;
                                          this.CheckRows[this.checkindex].rechk_dt = XEUtils.toDateString(new Date(), "yyyy-MM-dd");
                                          this.CheckRows[this.checkindex].cp_msg = "审核成功,CA签名失败!";
                                          this.checkindex++;
                                          this.checkcafail++;
                                          this.$pub.Log("LIS330 批次审核: 审核报告置值结束 审核成功" + row.reportid);
                                          if(this.aftercheckautoprint == "1") this.singleprint(row.reportid);
                                          if (this.checkindex < this.CheckRows.length) this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                                          else {
                                              this.xTable1loading = false;
                                              this.AlertMsg();
                                          }
                                      });
                              }
                          } else {
                              if (this.txtpeacefalmod == "1") {
                                  //this.CheckRows[this.checkindex].cp_msg = "审核失败";
                                  if (res.msg.errorMsg != null && res.msg.errorMsg.length > 0) {
                                      this.CheckRows[this.checkindex].cp_msg = "审核失败:" + res.msg.errorMsg[0].content;
                                  } else {
                                      this.CheckRows[this.checkindex].cp_msg = "审核失败";
                                  }

                                  this.CheckRows[this.checkindex].cp_flag = -1;
                                  this.checkindex++;
                                  this.checkfail++;
                                  this.$pub.Log("LIS330 批次审核: 审核报告置值结束 审核失败" + row.reportid);
                                  if (this.checkindex < this.CheckRows.length) this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                                  else {
                                      this.xTable1loading = false;
                                      this.AlertMsg();
                                  }
                              } else {
                                  this.ErrorListDeal(res.msg, res.flag, res.alertflag)
                                      .then(() => {
                                          if (res.alertflag == "1") {
                                              this.reportid = row.reportid;
                                              this.rptunitid = row.rptunitid;
                                              this.dialogDangerVisible = true;
                                              this.CurrentCheckUser = { userno: rckuser, username: rckusername };
                                          } else {
                                              this.CheckReportRequest("", "", row)
                                                  .then(() => {
                                                      this.ReportCheckCA(res, "", rckuser)
                                                          .then(() => {
                                                              this.CheckRows[this.checkindex].rechk_user = rckusername;
                                                              this.CheckRows[this.checkindex].rechk_dt = XEUtils.toDateString(new Date(), "yyyy-MM-dd");
                                                              this.CheckRows[this.checkindex].cp_msg = "审核成功";
                                                              this.checkindex++;
                                                              this.checksuccess++;
                                                              this.$pub.Log("LIS330 批次审核: 审核报告置值结束 审核成功" + row.reportid);
                                                              if(this.aftercheckautoprint == "1") this.singleprint(row.reportid);
                                                              if (this.checkindex < this.CheckRows.length) this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                                                              else {
                                                                  this.xTable1loading = false;
                                                                  this.AlertMsg();
                                                              }
                                                          })
                                                          .catch(() => {
                                                              this.CheckRows[this.checkindex].rechk_user = rckusername;
                                                              this.CheckRows[this.checkindex].rechk_dt = XEUtils.toDateString(new Date(), "yyyy-MM-dd");
                                                              this.CheckRows[this.checkindex].cp_msg = "审核成功,CA签名失败";
                                                              this.checkindex++;
                                                              this.checkcafail++;
                                                              this.$pub.Log("LIS330 批次审核: 审核报告置值结束 审核成功,CA失败 " + row.reportid);
                                                              if(this.aftercheckautoprint == "1") this.singleprint(row.reportid);
                                                              if (this.checkindex < this.CheckRows.length) this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                                                              else {
                                                                  this.xTable1loading = false;
                                                                  this.AlertMsg();
                                                              }
                                                          });
                                                  })
                                                  .catch((ex) => {
                                                      //this.CheckRows[this.checkindex].cp_msg = "审核失败:" + ex;
                                                      if (res.msg.errorMsg != null && res.msg.errorMsg.length > 0) {
                                                          this.CheckRows[this.checkindex].cp_msg = "审核失败:" + res.msg.errorMsg[0].content;
                                                      } else {
                                                          this.CheckRows[this.checkindex].cp_msg = "审核失败";
                                                      }

                                                      this.CheckRows[this.checkindex].cp_flag = -1;
                                                      this.checkindex++;
                                                      this.checkfail++;
                                                      this.$pub.Log("LIS330 批次审核: 审核报告置值结束 审核失败 " + row.reportid);
                                                      if (this.checkindex < this.CheckRows.length) this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                                                      else {
                                                          this.xTable1loading = false;
                                                          this.AlertMsg();
                                                      }
                                                  });
                                          }
                                      })
                                      .catch((ex) => {
                                          //this.CheckRows[this.checkindex].cp_msg = "审核失败";
                                          if (res.msg.errorMsg != null && res.msg.errorMsg.length > 0) {
                                              this.CheckRows[this.checkindex].cp_msg = "审核失败:" + res.msg.errorMsg[0].content;
                                          } else {
                                              this.CheckRows[this.checkindex].cp_msg = "审核失败";
                                          }
                                          this.CheckRows[this.checkindex].cp_flag = -1;
                                          this.checkindex++;
                                          this.checkfail++;
                                          this.$pub.Log("LIS330 批次审核: 审核报告置值结束 审核失败 " + row.reportid);
                                          if (this.checkindex < this.CheckRows.length) this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                                          else {
                                              this.xTable1loading = false;
                                              this.AlertMsg();
                                          }
                                      });
                              }
                          }
                      })
                      .catch((error) => {
                          this.$message.error("错误:" + error.message);
                      });
              } else {
                  //this.CheckRows[this.checkindex].cp_msg = "审核失败";
                  console.info("22222222");
                  this.CheckRows[this.checkindex].cp_msg = "审核失败:" + cares.msg;
                  this.CheckRows[this.checkindex].cp_flag = -1;
                  this.checkindex++;
                  this.checkfail++;
                  if (this.checkindex < this.CheckRows.length) this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                  else {
                      this.AlertMsg();
                  }
              }
          });
      },
      singleprint(selreportid){
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS330",
                  method: "post",
                  data: {
                      action: "getrptstyleid",
                      reportid: selreportid,
                  },
              })
              .then((res) => {
                  if (res != "")
                      //调整
                      this.$pub.printreport(this, selreportid, "1", res);
              });
      },
      //危急值上报
      CheckDangerDeal(alertinfo, type) {
          this.CheckReportRequest(type, alertinfo, this.CheckRows[this.checkindex])
              .then((res) => {
                  let row = this.CheckRows[this.checkindex];
                  let rckuser = !row.rechk_user ? this.CheckUser : row.rechk_user;
                  let rckusername = !row.rechk_username ? this.CheckUserName : row.rechk_username;
                  if (this.rechkcoverechkuser == "1") {
                      rckuser = this.CheckUser;
                      rckusername = this.CheckUserName;
                  }
                  this.ReportCheckCA(res, "", rckuser)
                      .then(() => {
                          this.CheckRows[this.checkindex].rechk_user = rckusername;
                          this.CheckRows[this.checkindex].rechk_dt = XEUtils.toDateString(new Date(), "yyyy-MM-dd");
                          this.CheckRows[this.checkindex].cp_msg = "审核成功";
                          this.checkindex++;
                          this.checksuccess++;
                          if(this.aftercheckautoprint == "1") this.singleprint(row.reportid);
                          if (this.checkindex < this.CheckRows.length) this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                          else this.AlertMsg();
                      })
                      .catch(() => {
                          this.CheckRows[this.checkindex].rechk_user = rckusername;
                          this.CheckRows[this.checkindex].rechk_dt = XEUtils.toDateString(new Date(), "yyyy-MM-dd");
                          this.CheckRows[this.checkindex].cp_msg = "审核成功,CA签名失败!";
                          this.checkindex++;
                          this.checkcafail++;
                          if(this.aftercheckautoprint == "1") this.singleprint(row.reportid);
                          if (this.checkindex < this.CheckRows.length) this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                          else this.AlertMsg();
                      });
              })
              .catch((ex) => {
                  //this.CheckRows[this.checkindex].cp_msg = "审核失败";
                  if (res.msg.errorMsg != null && res.msg.errorMsg.length > 0) {
                      this.CheckRows[this.checkindex].cp_msg = "审核失败:" + res.msg.errorMsg[0].content;
                  } else {
                      this.CheckRows[this.checkindex].cp_msg = "审核失败";
                  }
                  this.CheckRows[this.checkindex].cp_flag = -1;
                  this.checkindex++;
                  this.checkfail++;
                  if (this.checkindex < this.CheckRows.length) this.BeforeCheckReport(this.CheckRows[this.checkindex]);
                  else this.AlertMsg();
              });
      },
      CheckReportRequest(alertreportflag, alertinfo, row) {
          let rckuser = !row.rechk_user ? this.CheckUser : row.rechk_user;
          let rckusername = !row.rechk_username ? this.CheckUserName : row.rechk_username;
          if (this.rechkcoverechkuser == "1") {
              rckuser = this.CheckUser;
              rckusername = this.CheckUserName;
          }
          //this.$pub.Log("LIS330 批次审核: 审核报告exec开始 " + row.reportid);
          this.$pub.Log("LIS330 批次审核：审核报告exec开始 检验用户=" + row.report_user + ",审核用户=" + rckuser + ",reportid = " + row.reportid);
          return new Promise((s, f) => {
              this.$tool
                  .request({
                      url: "LIS/LIS3/LIS310",
                      method: "post",
                      data: {
                          action: "execcheckreport",
                          reportid: row.reportid,
                          reportuser: row.report_user,
                          checkuser: rckuser,
                          inputmsg: this.InputMsg,
                          alertreportflag: alertreportflag,
                          alertinfo: alertinfo,
                      },
                  })
                  .then((res) => {
                      this.$pub.Log("LIS330 批次审核: 审核报告后台请求结束 " + row.reportid);
                      if (res.flag == "1") {
                          if (this.dialogDangerVisible) {
                              this.dialogDangerVisible = false;
                          }
                          s(res);
                      } else {
                          this.ErrorListDeal(res.msg, res.flag)
                              .then(() => {
                                  f();
                              })
                              .catch(() => {
                                  f();
                              });
                      }
                  })
                  .catch((error) => {
                      this.$message.error("错误:" + error.message);
                      f();
                  });
          });
      },
      UnCheckReport() {
          var rows = this.$refs.xTable1.getSelectRecords();
          this.UnCheckRows = rows;
          this.Uncheckindex = 0;
          var hasrows = this.UnCheckRows.filter((item) => item.reportid != "");
          if (hasrows.length == 0) {
              this.$alert("没有选中需要解除审核的报告!", "提示");
              return;
          }
          var checkrows = this.UnCheckRows.filter((item) => item.rechkflag == "9");
          if (checkrows.length == 0) {
              this.$alert("选中报告已经全部解除审核", "提示");
              return;
          }
          this.Uncheckindex = this.UnCheckRows.indexOf(checkrows[0]);
          if (this.CheckUser) {
              this.BeforeUnCheckReport(this.UnCheckRows[this.Uncheckindex], this.CheckUser);
          } else {
              this.$rm_Login({
                  type: "用户登录验证",
                  btn: {
                      confirmBtnText: "确定",
                      cancelBtnText: "取消",
                  },
              }).then((res) => {
                  if (res.flag == "1") {
                      this.CheckUser = res.userid;
                      this.CheckUserName = res.username;
                      this.BeforeUnCheckReport(this.UnCheckRows[this.Uncheckindex], res.userid);
                  } else {
                      //登陆失败
                  }
              });
          }
      },
      BeforeUnCheckReport(row, userno) {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS310",
                  method: "post",
                  data: {
                      action: "uncheckreport",
                      reportid: row.reportid,
                      userno: userno,
                  },
              })
              .then((res) => {
                  if (res.flag == 1) {
                      if (res.otherflag == 1) {
                          if (this.txtpeacefalmod == "1") {
                              // this.UnCheckRows[this.Uncheckindex].cp_msg = "解除审核失败";
                              if (res.msg.errorMsg.length > 0) {
                                  this.UnCheckRows[this.Uncheckindex].cp_msg = "解审失败:" + res.msg.errorMsg[0].content;
                              } else if (res.msg.confirmDefNoMsg.length > 0) {
                                  this.UnCheckRows[this.Uncheckindex].cp_msg = "解审失败:" + res.msg.confirmDefNoMsg[0].content;
                              } else {
                                  this.UnCheckRows[this.Uncheckindex].cp_msg = "解审失败";
                              }
                              this.UnCheckRows[this.Uncheckindex].cp_flag = -1;
                              this.Uncheckindex++;
                              this.uncheckfail++;
                              if (this.Uncheckindex < this.UnCheckRows.length) this.BeforeUnCheckReport(this.UnCheckRows[this.Uncheckindex], this.CheckUser);
                              else {
                                  this.$alert("选中报告全部解除审核完毕!" + this.unchecksuccess + "条解除审核成功," + this.uncheckfail + "条解除审核失败", "提示");
                              }
                          } else {
                              this.UnCheckReportOther(userno, row);
                          }
                      } else {
                          this.UnCheckRows[this.Uncheckindex].rechk_user = "";
                          this.UnCheckRows[this.Uncheckindex].rechk_dt = "";
                          this.UnCheckRows[this.Uncheckindex].cp_msg = "解除审核成功";
                          this.Uncheckindex++;
                          this.unchecksuccess++;
                          if (this.Uncheckindex < this.UnCheckRows.length) this.BeforeUnCheckReport(this.UnCheckRows[this.Uncheckindex], this.CheckUser);
                          else {
                              this.$alert("选中报告全部解除审核完毕!" + this.unchecksuccess + "条解除审核成功," + this.uncheckfail + "条解除审核失败", "提示");
                          }
                      }
                  } else {
                      //=-1 错误消息的时候会进 catch
                      if (this.txtpeacefalmod == "1") {
                          //this.UnCheckRows[this.Uncheckindex].cp_msg = "解除审核失败";
                          if (res.msg.errorMsg.length > 0) {
                              this.UnCheckRows[this.Uncheckindex].cp_msg = "解审失败:" + res.msg.errorMsg[0].content;
                          } else if (res.msg.confirmDefNoMsg.length > 0) {
                              this.UnCheckRows[this.Uncheckindex].cp_msg = "解审失败:" + res.msg.confirmDefNoMsg[0].content;
                          } else {
                              this.UnCheckRows[this.Uncheckindex].cp_msg = "解审失败";
                          }

                          this.UnCheckRows[this.Uncheckindex].cp_flag = -1;
                          this.Uncheckindex++;
                          this.uncheckfail++;
                          if (this.Uncheckindex < this.UnCheckRows.length) this.BeforeUnCheckReport(this.UnCheckRows[this.Uncheckindex], this.CheckUser);
                          else {
                              this.$alert("选中报告全部解除审核完毕!" + this.unchecksuccess + "条解除审核成功," + this.uncheckfail + "条解除审核失败", "提示");
                          }
                      } else {
                          this.ErrorListDeal(res.msg, res.flag)
                              .then(() => {
                                  if (res.Item2 == 1) {
                                      this.UnCheckReportOther(userno, row);
                                  } else {
                                      this.UnCheckReportExec(userno, row);
                                  }
                              })
                              .catch(() => {
                                  // console.log("ErrorListDeal catch");
                              });
                      }
                  }
              });
      },
      UnCheckReportOther(userno, row) {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS310",
                  method: "post",
                  data: {
                      action: "uncheckreportotheroper",
                      reportid: row.reportid,
                      userno: userno,
                  },
              })
              .then((res) => {
                  //this.UnCheckRows[this.Uncheckindex].cp_msg = "解除审核失败";
                  if (res.msg.errorMsg.length > 0) {
                      this.UnCheckRows[this.Uncheckindex].cp_msg = "解审失败:" + res.msg.errorMsg[0].content;
                  } else if (res.msg.confirmDefNoMsg.length > 0) {
                      this.UnCheckRows[this.Uncheckindex].cp_msg = "解审失败:" + res.msg.confirmDefNoMsg[0].content;
                  } else {
                      this.UnCheckRows[this.Uncheckindex].cp_msg = "解审失败";
                  }

                  this.UnCheckRows[this.Uncheckindex].cp_flag = -1;
                  this.Uncheckindex++;
                  this.uncheckfail++;
                  if (this.Uncheckindex < this.UnCheckRows.length) this.BeforeUnCheckReport(this.UnCheckRows[this.Uncheckindex], this.CheckUser);
                  else {
                      this.$alert("选中报告全部解除审核完毕!" + this.unchecksuccess + "条解除审核成功," + this.uncheckfail + "条解除审核失败", "提示");
                  }
                  // if (res.Item1 == 1) {
                  // } else {
                  //     this.ErrorListDeal(res.Item2, res.Item1);
                  // }
              });
      },
      UnCheckReportExec(userno, row) {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS310",
                  method: "post",
                  data: {
                      action: "execuncheckreport",
                      reportid: row.reportid,
                      userno: userno,
                      inputmsg: this.InputMsg,
                  },
              })
              .then((res) => {
                  if (res.flag == "1") {
                      this.UnCheckRows[this.Uncheckindex].rechk_user = "";
                      this.UnCheckRows[this.Uncheckindex].rechk_dt = "";
                      this.UnCheckRows[this.Uncheckindex].cp_msg = "解除审核成功";
                      this.Uncheckindex++;
                      this.unchecksuccess++;
                      if (this.Uncheckindex < this.UnCheckRows.length) this.BeforeUnCheckReport(this.UnCheckRows[this.Uncheckindex], this.CheckUser);
                      else {
                          this.$alert("选中报告全部解除审核完毕!" + this.unchecksuccess + "条解除审核成功," + this.uncheckfail + "条解除审核失败", "提示");
                      }
                  } else {
                      //this.ErrorListDeal(res.msg, res.flag);
                      //this.UnCheckRows[this.Uncheckindex].cp_msg = "解除审核失败";
                      if (res.msg.errorMsg.length > 0) {
                          this.UnCheckRows[this.Uncheckindex].cp_msg = "解审失败:" + res.msg.errorMsg[0].content;
                      } else if (res.msg.confirmDefNoMsg.length > 0) {
                          this.UnCheckRows[this.Uncheckindex].cp_msg = "解审失败:" + res.msg.confirmDefNoMsg[0].content;
                      } else {
                          this.UnCheckRows[this.Uncheckindex].cp_msg = "解审失败";
                      }
                      this.UnCheckRows[this.Uncheckindex].cp_flag = -1;
                      this.Uncheckindex++;
                      this.uncheckfail++;
                      if (this.Uncheckindex < this.UnCheckRows.length) this.BeforeUnCheckReport(this.UnCheckRows[this.Uncheckindex], this.CheckUser);
                      else {
                          this.$alert("选中报告全部解除审核完毕!" + this.unchecksuccess + "条解除审核成功," + this.uncheckfail + "条解除审核失败", "提示");
                      }
                  }
              })
              .catch(() => {});
      },
      btnUnSign() {
          this.unchecksuccess = 0;
          this.uncheckfail = 0;
          var rows = this.$refs.xTable1.getSelectRecords();
          this.UnCheckRows = rows;
          this.Uncheckindex = 0;
          var hasrows = this.UnCheckRows.filter((item) => item.reportid != "");
          if (hasrows.length == 0) {
              this.$alert("没有选中需要解除签名的报告!", "提示");
              return;
          }
          var checkrows = this.UnCheckRows.filter((item) => item.rechkflag == "1");
          if (checkrows.length == 0) {
              this.$alert("选中报告已经全部解除签名", "提示");
              return;
          }
          this.Uncheckindex = this.UnCheckRows.indexOf(checkrows[0]);
          if (this.CheckUser) {
              this.UnSignReport(this.UnCheckRows[this.Uncheckindex], this.CheckUser);
          } else {
              this.$rm_Login({
                  type: "用户登录验证",
                  btn: {
                      confirmBtnText: "确定",
                      cancelBtnText: "取消",
                  },
              }).then((res) => {
                  if (res.flag == "1") {
                      this.CheckUser = res.userid;
                      this.CheckUserName = res.username;
                      this.UnSignReport(this.UnCheckRows[this.Uncheckindex]);
                  } else {
                      //登陆失败
                  }
              });
          }
      },
      //解除签名
      UnSignReport(row) {
          let rckuser = !row.rechk_user ? this.CheckUser : row.rechk_user;
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS333",
                  method: "post",
                  data: {
                      action: "unsignreport",
                      reportid: row.reportid,
                      checkuser: rckuser,
                  },
              })
              .then((res) => {
                  if (res.flag == 1) {
                      this.UnCheckRows[this.Uncheckindex].report_user = "";
                      this.UnCheckRows[this.Uncheckindex].report_dt = "";
                      this.UnCheckRows[this.Uncheckindex].cp_msg = "解除签名成功";
                      this.Uncheckindex++;
                      this.unchecksuccess++;
                      if (this.Uncheckindex < this.UnCheckRows.length) this.UnSignReport(this.UnCheckRows[this.Uncheckindex]);
                      else {
                          this.$alert("选中报告全部解除签名完毕!" + this.unchecksuccess + "条解除签名成功," + this.uncheckfail + "条解除签名失败", "提示");
                      }
                  } else {
                      //=-1 错误消息的时候会进 catch
                      if (this.txtpeacefalmod == "1") {
                          this.UnCheckRows[this.Uncheckindex].cp_msg = "解除签名失败";
                          this.Uncheckindex++;
                          this.uncheckfail++;
                          if (this.Uncheckindex < this.UnCheckRows.length) this.UnSignReport(this.UnCheckRows[this.Uncheckindex]);
                          else {
                              this.$alert("选中报告全部解除签名完毕!" + this.unchecksuccess + "条解除签名成功," + this.uncheckfail + "条解除签名失败", "提示");
                          }
                      } else {
                          this.ErrorListDeal(res.msg, res.flag)
                              .then(() => {})
                              .catch(() => {
                                  // console.log("ErrorListDeal catch");
                              });
                      }
                  }
              });
      },
      ErrorListDeal(msg, flag, type, func) {
          return new Promise((s, f) => {
              //msg消息列表
              //flag返回值标志
              //func确定后执行的函数
              //type为0是普通，type为1是危急值上报弹窗
              this.InputMsg = [];

              // 错误消息也使用消息列表回看

              // if (flag == -1) {
              //     //错误消息
              //     //if (msg.errorMsg.length > 0) {
              //     this.ErrorCPOne(0, msg.errorMsg, 0, func).then(() => {
              //         f(); //错误消息的模式下进入 catch ，逻辑上就和用户选择了取消一样
              //     });
              //     //}
              // }
              if (flag == 2) {
                  // 提示消息，只要显示一下就可以
                  //if (msg.showMsg.length > 0) {
                  this.ErrorCPOne(0, msg.showMsg, 0, func).then(() => {
                      s();
                  });
                  //}
              }
              //if (flag == -2 || flag == -3 || flag == 4) {
              if (flag == -1 || flag == -2 || flag == -3 || flag == 4) {
                  // -2 -3 是确认消息 4 是需要录入的消息
                  var msglist = [];
                  if (msg.errorMsg) {
                      for (let i = 0; i < msg.errorMsg.length; i++) {
                          msg.errorMsg[i].errflag = "1";
                          msglist.push(msg.errorMsg[i]);
                      }
                  }
                  if (msg.confirmDefNoMsg) {
                      for (let i = 0; i < msg.confirmDefNoMsg.length; i++) {
                          var attr = this.combineArr.find((item) => item.title == msg.confirmDefNoMsg[i].title && item.content == msg.confirmDefNoMsg[i].content);
                          if (attr == undefined) {
                              msglist.push(msg.confirmDefNoMsg[i]);
                          }
                      }
                  }
                  if (msg.confirmDefYesMsg) {
                      for (let i = 0; i < msg.confirmDefYesMsg.length; i++) {
                          if (!this.combineArr.find((item) => item.title == msg.confirmDefYesMsg[i].title && item.content == msg.confirmDefYesMsg[i].content)) {
                              msglist.push(msg.confirmDefYesMsg[i]);
                          }
                      }
                  }
                  if (msg.inputMsg && msg.inputMsg.length > 0) {
                      for (let i = 0; i < msg.inputMsg.length; i++) {
                          msglist.push(msg.inputMsg[i]);
                          this.InputMsg.push({ keycode: msg.inputMsg[i].keycode, msg: { title: "", content: "" } });
                      }
                  }

                  if (msglist.length == 1) {
                      if (msg.errorMsg.length > 0) {
                          this.ErrorCPOne(0, msglist, 0, func).then(() => {
                              f();
                          });
                      } else if (msg.confirmDefNoMsg.length > 0) {
                          this.ErrorCPOne(3, msglist, 0, func)
                              .then(() => {
                                  s();
                              })
                              .catch(() => {
                                  f();
                              });
                      } else if (msg.confirmDefYesMsg.length > 0) {
                          this.ErrorCPOne(2, msglist, 0, func)
                              .then(() => {
                                  s();
                              })
                              .catch(() => {
                                  f();
                              });
                      } else {
                          this.ErrorCPOne(1, msg.inputMsg, 0, func)
                              .then(() => {
                                  s();
                              })
                              .catch(() => {
                                  f();
                              });
                      }
                  } else {
                      this.ErrorCPOne(4, msglist, 0, func)
                          .then(() => {
                              s();
                          })
                          .catch(() => {
                              f();
                          });
                  }
              }
          });
      },
      ErrorCPOne(type, list, i, func) {
          //type=0 显示消息，type=1 输入消息，type=2 焦点在是提示消息,type=3 焦点在否提示消息
          return new Promise((s, f) => {
              if (list.length == 0) {
                  s();
              } else if (list.length == 1) {
                  if (type != 1) {
                      // this.$confirm(list[i].content ? list[i].content : "错误", list[i].title ? list[i].title : "提示", {
                      //     confirmButtonText: "确定",
                      //     cancelButtonText: "取消",
                      //     focusCancelButton: false,
                      //     closeOnClickModal: false,
                      //     showCancelButton: false,
                      //     type: "warning"
                      // })
                      //     .then(the => {
                      //         s();
                      //     })
                      //     .catch(cat => {
                      //         //只是显示的消息，没有取消按钮 无论如何都应该都进.then  s()
                      //         s();
                      //     });
                      // } else if (type == 2 || type == 3) {
                      if (this.combineArr.find((item) => item.title == list[i].title && item.content == list[i].content)) {
                          s();
                          return;
                      }
                      this.SingleMsgTitle = list[i].title ? list[i].title : "提示";
                      this.SingleMsgContent = list[i].content ? list[i].content : "错误";
                      this.ShowCancel = type != 0;
                      this.focusOnCancel = type == 3;
                      this.IgnoreFlag = true;
                      this.$refs.singlemsgdialog
                          .ShowDialog()
                          .then(() => {
                              if (this.IgnoreFlag && !this.combineArr.find((item) => item.title == list[i].title && item.content == list[i].content)) {
                                  this.combineArr.push({ title: list[i].title, content: list[i].content });
                              }
                              s();
                          })
                          .catch(() => {
                              if (type == 0) {
                                  if (this.IgnoreFlag && !this.combineArr.find((item) => item.title == list[i].title && item.content == list[i].content)) {
                                      this.combineArr.push({ title: list[i].title, content: list[i].content });
                                  }
                                  s();
                              } else {
                                  f();
                              }
                          });
                      // this.$confirm(list[i].content ? list[i].content : "错误", list[i].title ? list[i].title : "提示", {
                      //     confirmButtonText: "确定",
                      //     cancelButtonText: "取消",
                      //     focusCancelButton: type == 3,
                      //     closeOnClickModal: false,
                      //     type: "warning"
                      // })
                      //     .then(() => {
                      //         // if (list[i].title == "审核条件不通过" && this.combineArr.indexOf(list[i].content) == -1) {
                      //         //     this.combineArr.push(list[i].content);
                      //         // }
                      //         s();
                      //     })
                      //     .catch(cat => {
                      //         f(); //一旦用户选择了【取消】则直接退出
                      //     });
                  } else if (type == 1) {
                      if (list[i].msg.content.indexOf("解除审核") > -1) {
                          this.inputkeycode = list[i].keycode;
                          this.unreasoncheckmsg = "";
                          this.SingleSubmitdisabled = true;
                          this.$refs.uncheckdialog
                              .ShowDialog()
                              .then(() => {
                                  var data = this.InputMsg.find((item) => item.keycode == this.inputkeycode);
                                  data.msg.content = this.unreasoncheckmsg;
                                  s();
                              })
                              .catch(() => {
                                  f();
                              });
                      } else {
                          this.$prompt("请输入" + list[i].msg.content, list[i].msg.title ? list[i].msg.title : "提示", {
                              confirmButtonText: "确定",
                              cancelButtonText: "取消",
                              showCancelButton: false,
                              cancelButtonClass: "el-button el-button--default el-button--small el-button--primary",
                              confirmButtonClass: "el-button el-button--default el-button--small",
                              focusCancelButton: false,
                              closeOnClickModal: false,
                              inputValidator: (v) => {
                                  if (!v || v == "" || v == null) return "输入的内容不能为空";
                              },
                              beforeClose: (action, instance, done) => {
                                  if (action === "confirm") {
                                      done();
                                  } else {
                                      f();
                                      done();
                                  }
                              },
                          }).then(({ value }) => {
                              var onemsg = this.InputMsg.filter((item) => item.keycode == list[i].keycode);

                              if (onemsg && onemsg.length > 0) {
                                  onemsg[0].msg.content = value;
                              }
                              s();
                          });
                      }
                  } else {
                      s();
                  }
              } else {
                  //多消息先不管后续忽略了
                  if (list) this.TotalMsgNo = list.length;
                  this.NowMsgNo = 1;
                  this.MsgAllOver = true;
                  if (this.InputMsg.length == 0) this.Submitdisabled = false;
                  else this.Submitdisabled = true;
                  this.msglist = list;
                  if (this.msglist[0].kind == "错误") this.Submitdisabled = true;
                  this.inmsg = "";
                  this.msglist.forEach(item =>{
                      if(item.content) item.content = item.content.replace(/\r\n/g,"<br/>")
                  });
                  this.$refs.msgdialog
                      .ShowDialog()
                      .then(() => {
                          //可以点确认代表没有错误消息并且输入消息也已经输入
                          let needlogin = list.find((item) => item.content && item.content.indexOf("（需登录）") > -1);
                          //如果确认消息需要登录
                          if(needlogin)
                          {
                              this.$rm_Login({
                                  type: "用户登录验证",
                                  btn: {
                                      confirmBtnText: "确定",
                                      cancelBtnText: "取消",
                                  },
                              })
                                  .then((res) => {
                                      if (res.flag == "1") {
                                          s();
                                      } else {
                                          //登录失败
                                          this.$message.error("用户登录失败");
                                          f();
                                      }
                                  })
                                  .catch((e) => {
                                      f();//取消登录也不让他继续
                                  });
                          } else {
                              s();//不需要登录的就正常下一步
                          }
                      })
                      .catch(() => {
                          f();
                      });
              }
          });
      },
      Uncheckchange(code, name) {
          if (this.inputkeycode) {
              this.unreasoncheckmsg = name;
              this.inmsg = name;
              this.SingleSubmitdisabled = false;
          }
          this.dialogUncheckReasonDataVisible = false;
      },
      msgDblClick(content, keycode) {
          if (keycode) this.inputkeycode = keycode;
          this.dialogUncheckReasonDataVisible = true;
      },
      uncheckInput(val) {
          if (val) this.SingleSubmitdisabled = false;
          else this.SingleSubmitdisabled = true;
      },
      SaveInputMsg(keycode) {
          if(this.inmsg == ""){
              this.$alert("输入的内容不能为空!", "提示", {
                  confirmButtonText: "确定",
              });
              return;
          }
          this.Submitdisabled = false;
          var onemsg = this.InputMsg.filter((i) => i.keycode == keycode);
          if (onemsg && onemsg.length > 0) onemsg[0].msg.content = this.inmsg;
      },
      MsgCarouselChange(val) {
          if (this.msglist[val].hasOwnProperty("keycode") && this.msglist[val].keycode) {
              var onemsg = this.InputMsg.filter((i) => i.keycode == this.msglist[val].keycode);
              if (onemsg && onemsg.length > 0) this.inmsg = onemsg[0].msg.content;
              else this.inmsg = "";
          }
          this.NowMsgNo = val - 0 + 1;
          this.msgtitle = this.msglist[val].title;
          if (this.NowMsgNo == this.TotalMsgNo) this.MsgAllOver = false;
      },
      //CA
      ReportCheckCA(res, tp, rechkuser) {
          return new Promise((s, f) => {
              if (res.hasOwnProperty("checkca") && res.checkca == "1") {
                  //CA信息保存先异步吧，和审核报告区分开来，就算签名失败也不影响审核，以免以后CA出故障导致一直无法审核报告
                  let chkuser = rechkuser;
                  //CA签名数据保存，不管成功或失败，都不影响审核 加密和保存加密数据都集成到CAsign方法
                  this.$ca.CAsign(chkuser, res.reporttoca.data, res.reporttoca.reportid).then((caret) => {
                      //this.$pub.Log("电子签名结束");
                      if (caret.flag != "1") {
                          this.$pub.Log("CA签名失败：chkuser=" + chkuser + "reportid = " + res.reporttoca.reportid + ",data=" + res.reporttoca.data);
                          if (this.txtpeacefalmod == "1") {
                              f();
                          } else {
                              this.$alert("CA[电子签名]认证或记录失败，您可以稍后手工补电子签名，或解除审核后重新审核！ " + caret.msg, "CA签名失败！").finally(() => {
                                  f();
                              });
                          }
                      } else {
                          s();
                      }
                  });
              } else {
                  s();
              }
          });
      },
      AlertMsg() {
          if (this.checkcafail > 0) {
              this.$alert("选中报告全部审核完毕!" + this.checksuccess + "条审核成功," + this.checkfail + "条审核失败," + this.checkcafail + "条审核成功,CA签名失败", "提示");
          } else {
              this.$alert("选中报告全部审核完毕!" + this.checksuccess + "条审核成功," + this.checkfail + "条审核失败", "提示");
          }
      },
      ResultClass1(row) {
          var stylestr = "";
          if (row.cp_flag <= -1) {
              stylestr = "padding:0 3px;background-color:#FFC0CB";
          }
          return stylestr;
      },
  },
  watch: {
      dialogSingleMsgVisible(val) {
          if (val) {
              this.$nextTick(() => {
                  if (this.focusOnCancel) {
                      this.$refs.cancel.$el.focus();
                  } else {
                      this.$refs.confirm.$el.focus();
                  }
              });
          }
      },
  },
};
</script>

<style scoped>
.pagetop {
  width: 100%;
  /* height: 95px; */
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 120px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}
/deep/ .vxe-table .vxe-body--column.col-red {
  color: red;
}
/deep/ .vxe-table .vxe-body--column.col-yellow {
  background-color: yellow;
}
/deep/ .vxe-table .vxe-body--column.col-green {
  background-color: #00ff00;
}
/deep/.vxe-cell .el-checkbox__inner::after {
  border: 2px solid #000000 !important;
  box-sizing: content-box;
  content: "";
  border-left: 0 !important;
  border-top: 0 !important;
  height: 7px;
  left: 4px;
  position: absolute;
  top: 1px;
  transform: rotate(45deg) scaleY(0);
  width: 3px;
  transition: transform 0.15s ease-in 0.05s;
  transform-origin: center;
}
/deep/.vxe-cell .el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #000000;
  cursor: not-allowed;
}
/deep/.vxe-cell .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
  background-color: #ffffff !important;
}
/deep/.fail {
  color: #ff0000;
}
</style>
